package agricultural;

import observer.Observer;
import strategy.WorkStrategy;

public abstract class AgriculturalMachine implements Observer {
    protected String machineId;
    protected WorkStrategy workStrategy;
    protected String location; // 位置
    protected double fuel; // 油量
    protected String operationStatus; // 作业状态

    public AgriculturalMachine(String machineId) {
        this.machineId = machineId;
        this.location = "未知位置";
        this.fuel = 100;
        this.operationStatus = "闲置";
    }

    public void setWorkStrategy(WorkStrategy workStrategy) {
        this.workStrategy = workStrategy;
        System.out.println(machineId + "更新作业策略为: " + workStrategy.getClass().getSimpleName());
    }

    public void performWork() {
        if (workStrategy != null) {
            workStrategy.execute(machineId);
        } else {
            System.out.println(machineId + "没有设置作业策略");
        }
    }

    public String getMachineId() {
        return machineId;
    }

    public abstract void adjustToEnvironment(double soilMoisture, int cropGrowthStatus, String weatherData);

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
        System.out.println(machineId + "位置更新为: " + location);
    }

    public double getFuel() {
        return fuel;
    }

    public void setFuel(double fuel) {
        this.fuel = fuel;
        System.out.println(machineId + "油量更新为: " + fuel + "%");
    }

    public String getOperationStatus() {
        return operationStatus;
    }

    public void setOperationStatus(String operationStatus) {
        this.operationStatus = operationStatus;
        System.out.println(machineId + "作业状态更新为: " + operationStatus);
    }

    public void receiveRemoteCommand(String command) {
        System.out.println(machineId + "收到远程控制指令: " + command);
        // 这里可以根据指令执行相应的操作
    }
}